#ifndef MDSHOW_H
#define MDSHOW_H

#ifdef GNU_C
#ifdef WIN32

#include <dshow.h>
#include <ocidl.h>
#include <process.h>

DEFINE_GUID(CLSID_CaptureGraphBuilder2,0xbf87b6e1,0x8c27,0x11d0,0xb3,0xf0,0x00,0xaa,0x00,0x37,0x61,0xc5);
DEFINE_GUID(CLSID_FilterGraph,0xe436ebb3,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70);
DEFINE_GUID(CLSID_NullRenderer,0xc1f400a4,0x3f08,0x11d3,0x9f,0x0b,0x00,0x60,0x08,0x03,0x9e,0x37);
DEFINE_GUID(CLSID_SampleGrabber,0xc1f400a0,0x3f08,0x11d3,0x9f,0x0b,0x00,0x60,0x08,0x03,0x9e,0x37);
DEFINE_GUID(CLSID_SystemDeviceEnum,0x62be5d10,0x60eb,0x11d0,0xbd,0x3b,0x00,0xa0,0xc9,0x11,0xce,0x86);
DEFINE_GUID(CLSID_VideoInputDeviceCategory,0x860bb310,0x5d01,0x11d0,0xbd,0x3b,0x00,0xa0,0xc9,0x11,0xce,0x86);
DEFINE_GUID(FORMAT_VideoInfo,0x05589f80,0xc356,0x11ce,0xbf,0x01,0x00,0xaa,0x00,0x55,0x59,0x5a);
DEFINE_GUID(IID_IAMAnalogVideoDecoder,0xc6e13350,0x30ac,0x11d0,0xa1,0x8c,0x00,0xa0,0xc9,0x11,0x89,0x56);
DEFINE_GUID(IID_IAMCameraControl,0xc6e13370,0x30ac,0x11d0,0xa1,0x8c,0x00,0xa0,0xc9,0x11,0x89,0x56);
DEFINE_GUID(IID_IAMCrossbar,0xc6e13380,0x30ac,0x11d0,0xa1,0x8c,0x00,0xa0,0xc9,0x11,0x89,0x56);
DEFINE_GUID(IID_IAMStreamConfig,0xc6e13340,0x30ac,0x11d0,0xa1,0x8c,0x00,0xa0,0xc9,0x11,0x89,0x56);
DEFINE_GUID(IID_IAMVideoProcAmp,0xc6e13360,0x30ac,0x11d0,0xa1,0x8c,0x00,0xa0,0xc9,0x11,0x89,0x56);
DEFINE_GUID(IID_IBaseFilter,0x56a86895,0x0ad4,0x11ce,0xb0,0x3a,0x00,0x20,0xaf,0x0b,0xa7,0x70);
DEFINE_GUID(IID_ICaptureGraphBuilder2,0x93e5a4e0,0x2d50,0x11d2,0xab,0xfa,0x00,0xa0,0xc9,0xc6,0xe3,0x8d);
DEFINE_GUID(IID_ICreateDevEnum,0x29840822,0x5b84,0x11d0,0xbd,0x3b,0x00,0xa0,0xc9,0x11,0xce,0x86);
DEFINE_GUID(IID_IGraphBuilder,0x56a868a9,0x0ad4,0x11ce,0xb0,0x3a,0x00,0x20,0xaf,0x0b,0xa7,0x70);
DEFINE_GUID(IID_IMPEG2PIDMap,0xafb6c2a1,0x2c41,0x11d3,0x8a,0x60,0x00,0x00,0xf8,0x1e,0x0e,0x4a);
DEFINE_GUID(IID_IMediaControl,0x56a868b1,0x0ad4,0x11ce,0xb0,0x3a,0x00,0x20,0xaf,0x0b,0xa7,0x70);
DEFINE_GUID(IID_IMediaFilter,0x56a86899,0x0ad4,0x11ce,0xb0,0x3a,0x00,0x20,0xaf,0x0b,0xa7,0x70);
DEFINE_GUID(IID_ISampleGrabber,0x6b652fff,0x11fe,0x4fce,0x92,0xad,0x02,0x66,0xb5,0xd7,0xc7,0x8f);
DEFINE_GUID(LOOK_UPSTREAM_ONLY,0xac798be0,0x98e3,0x11d1,0xb3,0xf1,0x00,0xaa,0x00,0x37,0x61,0xc5);
DEFINE_GUID(MEDIASUBTYPE_AYUV,0x56555941,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
DEFINE_GUID(MEDIASUBTYPE_IYUV,0x56555949,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
DEFINE_GUID(MEDIASUBTYPE_RGB24,0xe436eb7d,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70);
DEFINE_GUID(MEDIASUBTYPE_RGB32,0xe436eb7e,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70);
DEFINE_GUID(MEDIASUBTYPE_RGB555,0xe436eb7c,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70);
DEFINE_GUID(MEDIASUBTYPE_RGB565,0xe436eb7b,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70);
DEFINE_GUID(MEDIASUBTYPE_UYVY,0x59565955,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
DEFINE_GUID(MEDIASUBTYPE_Y211,0x31313259,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
DEFINE_GUID(MEDIASUBTYPE_Y411,0x31313459,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
DEFINE_GUID(MEDIASUBTYPE_Y41P,0x50313459,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
DEFINE_GUID(MEDIASUBTYPE_YUY2,0x32595559,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
DEFINE_GUID(MEDIASUBTYPE_YUYV,0x56595559,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
DEFINE_GUID(MEDIASUBTYPE_YV12,0x32315659,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
DEFINE_GUID(MEDIASUBTYPE_YVU9,0x39555659,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
DEFINE_GUID(MEDIASUBTYPE_YVYU,0x55595659,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
DEFINE_GUID(MEDIATYPE_Interleaved,0x73766169,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
DEFINE_GUID(MEDIATYPE_Video,0x73646976,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
DEFINE_GUID(PIN_CATEGORY_CAPTURE,0xfb6c4281,0x0353,0x11d1,0x90,0x5f,0x00,0x00,0xc0,0xcc,0x16,0xba);
DEFINE_GUID(PIN_CATEGORY_PREVIEW,0xfb6c4282,0x0353,0x11d1,0x90,0x5f,0x00,0x00,0xc0,0xcc,0x16,0xba);
DEFINE_GUID(AMPROPSETID_Pin,0x9b00f101,0x1567,0x11d1,0xb3,0xf1,0x0,0xaa,0x0,0x37,0x61,0xc5);
DEFINE_GUID(IID_IKsPropertySet,0x31efac30,0x515c,0x11d0,0xa9,0xaa,0x00,0xaa,0x00,0x61,0xbe,0x93);
DEFINE_GUID(CLSID_Colour,0x1643e180,0x90f5,0x11ce,0x97,0xd5,0x00,0xaa,0x00,0x55,0x59,0x5a);
DEFINE_GUID(CLSID_SmartTee,0xcc58e280,0x8aa1,0x11d1,0xb3,0xf1,0x0,0xaa,0x0,0x37,0x61,0xc5);

typedef enum AMPROPERTY_PIN {
    AMPROPERTY_PIN_CATEGORY = 0,
    AMPROPERTY_PIN_MEDIUM   = 1
} AMPROPERTY_PIN;

typedef GUID *REFUID;

interface IAMStreamConfig : IUnknown
{
    virtual HRESULT STDMETHODCALLTYPE
    SetFormat(AM_MEDIA_TYPE *pmt);
    virtual HRESULT STDMETHODCALLTYPE
    GetFormat(AM_MEDIA_TYPE **pmt);
    virtual HRESULT STDMETHODCALLTYPE
    GetNumberOfCapabilities(int *piCount, int *piSize);
    virtual HRESULT STDMETHODCALLTYPE
    GetStreamCaps(int iIndex, AM_MEDIA_TYPE **pmt, BYTE *pSCC);
};

interface IAMCrossbar : IUnknown
{
    virtual HRESULT STDMETHODCALLTYPE
    get_PinCounts(long *OutputPinCount, long *InputPinCount);

    virtual HRESULT STDMETHODCALLTYPE
    CanRoute(long OutputPinIndex, long InputPinIndex);

    virtual HRESULT STDMETHODCALLTYPE
    Route(long OutputPinIndex, long InputPinIndex);

    virtual HRESULT STDMETHODCALLTYPE
    get_IsRoutedTo(long OutputPinIndex, long *InputPinIndex);

    virtual HRESULT STDMETHODCALLTYPE
    get_CrossbarPinInfo(BOOL IsInputPin, long PinIndex, long *PinIndexRelated, long *PhysicalType);
};

interface IFileSinkFilter : IUnknown
{
    virtual HRESULT STDMETHODCALLTYPE
    GetCurrentFile(LPOLESTR *ppszFileName, AM_MEDIA_TYPE *pmt);

    virtual HRESULT STDMETHODCALLTYPE
    SetCurrentFile(LPOLESTR pszFileName, const AM_MEDIA_TYPE *pmt);
};

interface IAMCopyCaptureFileProgress : IUnknown
{
    virtual HRESULT STDMETHODCALLTYPE
    Progress(int iProgress);
};

interface ICaptureGraphBuilder2 : IUnknown
{
    virtual HRESULT STDMETHODCALLTYPE
    SetFilterGraph(IGraphBuilder *pfg);

    virtual HRESULT STDMETHODCALLTYPE
    GetFilterGraph(IGraphBuilder **ppfg);

    virtual HRESULT STDMETHODCALLTYPE
    SetOutputFileName(const GUID*       pType,
                      LPCOLESTR         lpwstrFile,
                      IBaseFilter**     ppf,
                      IFileSinkFilter** pSink);

    virtual HRESULT STDMETHODCALLTYPE
    FindInterface(const GUID*  pCategory,
                  const GUID*  pType,
                  IBaseFilter* pf,
                  REFIID       riid,
                  void**       ppint);

    virtual HRESULT STDMETHODCALLTYPE
    RenderStream(const GUID*  pCategory,
                 const GUID*  pType,
                 IUnknown*    pSource,
                 IBaseFilter* pIntermediate,
                 IBaseFilter* pSink);

    virtual HRESULT STDMETHODCALLTYPE
    ControlStream(const GUID*     pCategory,
                  const GUID*     pType,
                  IBaseFilter*    pFilter,
                  REFERENCE_TIME* pstart,
                  REFERENCE_TIME* pstop,
                  WORD            wStartCookie,
                  WORD            wStopCookie);

    virtual HRESULT STDMETHODCALLTYPE
    AllocCapFile(LPCOLESTR lpwstr, DWORDLONG dwlSize);

    virtual HRESULT STDMETHODCALLTYPE
    CopyCaptureFile(LPOLESTR lpwstrOld,
                    LPOLESTR lpwstrNew,
                    int fAllowEscAbort,
                    IAMCopyCaptureFileProgress *pCallback);

    virtual HRESULT STDMETHODCALLTYPE
    FindPin(IUnknown*     pSource,
            PIN_DIRECTION pindir,
            const GUID*   pCategory,
            const GUID*   pType,
            BOOL          fUnconnected,
            int           num,
            IPin**        ppPin);
};

interface IKsPropertySet : IUnknown
{
    virtual HRESULT STDMETHODCALLTYPE
    Set(REFGUID guidPropSet,
        DWORD dwPropID,
        LPVOID pInstanceData,
        DWORD cbInstanceData,
        LPVOID pPropData,
        DWORD cbPropData);
    virtual HRESULT STDMETHODCALLTYPE
    Get(REFGUID guidPropSet,
        DWORD dwPropID,
        LPVOID pInstanceData,
        DWORD cbInstanceData,
        LPVOID pPropData,
        DWORD cbPropData,
        DWORD *pcbReturned);
    virtual HRESULT STDMETHODCALLTYPE
    QuerySupported(GUID *guidPropSet, DWORD dwPropID, DWORD *pTypeSupport);
};

interface IAMVideoProcAmp : IUnknown
{
    virtual HRESULT STDMETHODCALLTYPE
    GetRange(long Property,
             long *pMin,
             long *pMax,
             long *pSteppingDelta,
             long *pDefault,
             long *pCapsFlags);

    virtual HRESULT STDMETHODCALLTYPE
    Set(long Property,
        long lValue,
        long Flags);

    virtual HRESULT STDMETHODCALLTYPE
    Get(long Property,
        long * lValue,
        long * Flags);
};

interface ISampleGrabberCB : public IUnknown
{
    virtual STDMETHODIMP SampleCB(double SampleTime,IMediaSample *pSample) = 0;
    virtual STDMETHODIMP BufferCB(double SampleTime,BYTE *pBuffer,long BufferLen) = 0;
};


interface ISampleGrabber : public IUnknown
{
    virtual HRESULT STDMETHODCALLTYPE SetOneShot(BOOL OneShot) = 0;
    virtual HRESULT STDMETHODCALLTYPE SetMediaType(const AM_MEDIA_TYPE *pType) = 0;
    virtual HRESULT STDMETHODCALLTYPE GetConnectedMediaType(AM_MEDIA_TYPE *pType) = 0;
    virtual HRESULT STDMETHODCALLTYPE SetBufferSamples(BOOL BufferThem) = 0;
    virtual HRESULT STDMETHODCALLTYPE GetCurrentBuffer(long *pBufferSize,long *pBuffer) = 0;
    virtual HRESULT STDMETHODCALLTYPE GetCurrentSample(IMediaSample **ppSample) = 0;
    virtual HRESULT STDMETHODCALLTYPE SetCallback(ISampleGrabberCB *pCallback, long WhichMethodToCallback) = 0;
};

#endif
#else
#include <DShow.h>
#include <OCIdl.h>

#pragma comment(lib, "strmiids.lib")

DEFINE_GUID(CLSID_NullRenderer,0xc1f400a4,0x3f08,0x11d3,0x9f,0x0b,0x00,0x60,0x08,0x03,0x9e,0x37);
DEFINE_GUID(CLSID_SampleGrabber,0xc1f400a0,0x3f08,0x11d3,0x9f,0x0b,0x00,0x60,0x08,0x03,0x9e,0x37);
DEFINE_GUID(IID_ISampleGrabber,0x6b652fff,0x11fe,0x4fce,0x92,0xad,0x02,0x66,0xb5,0xd7,0xc7,0x8f);

interface ISampleGrabberCB : public IUnknown
{
    virtual STDMETHODIMP SampleCB(double SampleTime,IMediaSample *pSample) = 0;
    virtual STDMETHODIMP BufferCB(double SampleTime,BYTE *pBuffer,long BufferLen) = 0;
};

interface ISampleGrabber : public IUnknown
{
    virtual HRESULT STDMETHODCALLTYPE SetOneShot(BOOL OneShot) = 0;
    virtual HRESULT STDMETHODCALLTYPE SetMediaType(const AM_MEDIA_TYPE *pType) = 0;
    virtual HRESULT STDMETHODCALLTYPE GetConnectedMediaType(AM_MEDIA_TYPE *pType) = 0;
    virtual HRESULT STDMETHODCALLTYPE SetBufferSamples(BOOL BufferThem) = 0;
    virtual HRESULT STDMETHODCALLTYPE GetCurrentBuffer(long *pBufferSize,long *pBuffer) = 0;
    virtual HRESULT STDMETHODCALLTYPE GetCurrentSample(IMediaSample **ppSample) = 0;
    virtual HRESULT STDMETHODCALLTYPE SetCallback(ISampleGrabberCB *pCallback, long WhichMethodToCallback) = 0;
};
#endif
#endif // MDSHOW_H
